package com.itrus.util.sign;

import com.itrus.cryptorole.bc.RecipientBcImpl;
import com.itrus.cryptorole.bc.SenderBcImpl;
import com.itrus.svm.SignerAndEncryptedDigest;
import com.itrus.util.DERUtils;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import javax.security.auth.x500.X500Principal;
import org.bouncycastle.util.encoders.Base64;

public class RSAWithHardware
{
  private static String DINPAY_KEY_VERSION;
  private static File versionFile = null;
  private String DINPAY_CN = "E=tsm@ddbill.com, CN=DINPAY001, OU=技术部, O=智付电子支付有限公司";
  private RecipientBcImpl recipient = new RecipientBcImpl();
  private SenderBcImpl signSenderBc;

  // ERROR //
  private static void checkDinpayKeyVersion(String paramString)
  {
    // Byte code:
    //   0: aload_0
    //   1: ldc 35
    //   3: invokevirtual 41	java/lang/String:indexOf	(Ljava/lang/String;)I
    //   6: istore_1
    //   7: aconst_null
    //   8: astore_2
    //   9: iload_1
    //   10: ifle +16 -> 26
    //   13: aload_0
    //   14: iconst_5
    //   15: aload_0
    //   16: ldc 35
    //   18: invokevirtual 41	java/lang/String:indexOf	(Ljava/lang/String;)I
    //   21: iadd
    //   22: invokevirtual 45	java/lang/String:substring	(I)Ljava/lang/String;
    //   25: astore_2
    //   26: getstatic 47	com/itrus/util/sign/RSAWithHardware:DINPAY_KEY_VERSION	Ljava/lang/String;
    //   29: ifnull +176 -> 205
    //   32: ldc 49
    //   34: getstatic 47	com/itrus/util/sign/RSAWithHardware:DINPAY_KEY_VERSION	Ljava/lang/String;
    //   37: invokevirtual 53	java/lang/String:trim	()Ljava/lang/String;
    //   40: invokevirtual 57	java/lang/String:equals	(Ljava/lang/Object;)Z
    //   43: ifne +162 -> 205
    //   46: aload_2
    //   47: ifnull +15 -> 62
    //   50: ldc 49
    //   52: aload_2
    //   53: invokevirtual 53	java/lang/String:trim	()Ljava/lang/String;
    //   56: invokevirtual 57	java/lang/String:equals	(Ljava/lang/Object;)Z
    //   59: ifeq +13 -> 72
    //   62: new 59	java/lang/RuntimeException
    //   65: dup
    //   66: ldc 61
    //   68: invokespecial 63	java/lang/RuntimeException:<init>	(Ljava/lang/String;)V
    //   71: athrow
    //   72: aload_2
    //   73: invokevirtual 53	java/lang/String:trim	()Ljava/lang/String;
    //   76: astore 11
    //   78: getstatic 47	com/itrus/util/sign/RSAWithHardware:DINPAY_KEY_VERSION	Ljava/lang/String;
    //   81: aload 11
    //   83: invokevirtual 66	java/lang/String:compareTo	(Ljava/lang/String;)I
    //   86: istore 12
    //   88: iload 12
    //   90: ifle +13 -> 103
    //   93: new 59	java/lang/RuntimeException
    //   96: dup
    //   97: ldc 61
    //   99: invokespecial 63	java/lang/RuntimeException:<init>	(Ljava/lang/String;)V
    //   102: athrow
    //   103: iload 12
    //   105: ifge +40 -> 145
    //   108: aconst_null
    //   109: astore 13
    //   111: new 68	java/io/FileWriter
    //   114: dup
    //   115: getstatic 17	com/itrus/util/sign/RSAWithHardware:versionFile	Ljava/io/File;
    //   118: invokespecial 71	java/io/FileWriter:<init>	(Ljava/io/File;)V
    //   121: astore 14
    //   123: aload 14
    //   125: aload 11
    //   127: invokevirtual 74	java/io/FileWriter:write	(Ljava/lang/String;)V
    //   130: aload 14
    //   132: invokevirtual 77	java/io/FileWriter:flush	()V
    //   135: aload 14
    //   137: ifnull +8 -> 145
    //   140: aload 14
    //   142: invokevirtual 80	java/io/FileWriter:close	()V
    //   145: return
    //   146: astore 15
    //   148: aload 15
    //   150: invokevirtual 83	java/io/IOException:printStackTrace	()V
    //   153: aload 13
    //   155: ifnull -10 -> 145
    //   158: aload 13
    //   160: invokevirtual 80	java/io/FileWriter:close	()V
    //   163: return
    //   164: astore 18
    //   166: aload 18
    //   168: invokevirtual 83	java/io/IOException:printStackTrace	()V
    //   171: return
    //   172: astore 16
    //   174: aload 13
    //   176: ifnull +8 -> 184
    //   179: aload 13
    //   181: invokevirtual 80	java/io/FileWriter:close	()V
    //   184: aload 16
    //   186: athrow
    //   187: astore 17
    //   189: aload 17
    //   191: invokevirtual 83	java/io/IOException:printStackTrace	()V
    //   194: goto -10 -> 184
    //   197: astore 19
    //   199: aload 19
    //   201: invokevirtual 83	java/io/IOException:printStackTrace	()V
    //   204: return
    //   205: aload_2
    //   206: ifnull -61 -> 145
    //   209: ldc 49
    //   211: aload_2
    //   212: invokevirtual 53	java/lang/String:trim	()Ljava/lang/String;
    //   215: invokevirtual 57	java/lang/String:equals	(Ljava/lang/Object;)Z
    //   218: ifne -73 -> 145
    //   221: aload_2
    //   222: invokevirtual 53	java/lang/String:trim	()Ljava/lang/String;
    //   225: astore_3
    //   226: aconst_null
    //   227: astore 4
    //   229: new 68	java/io/FileWriter
    //   232: dup
    //   233: getstatic 17	com/itrus/util/sign/RSAWithHardware:versionFile	Ljava/io/File;
    //   236: invokespecial 71	java/io/FileWriter:<init>	(Ljava/io/File;)V
    //   239: astore 5
    //   241: aload 5
    //   243: aload_3
    //   244: invokevirtual 74	java/io/FileWriter:write	(Ljava/lang/String;)V
    //   247: aload 5
    //   249: invokevirtual 77	java/io/FileWriter:flush	()V
    //   252: aload 5
    //   254: ifnull -109 -> 145
    //   257: aload 5
    //   259: invokevirtual 80	java/io/FileWriter:close	()V
    //   262: return
    //   263: astore 10
    //   265: aload 10
    //   267: invokevirtual 83	java/io/IOException:printStackTrace	()V
    //   270: return
    //   271: astore 6
    //   273: aload 6
    //   275: invokevirtual 83	java/io/IOException:printStackTrace	()V
    //   278: aload 4
    //   280: ifnull -135 -> 145
    //   283: aload 4
    //   285: invokevirtual 80	java/io/FileWriter:close	()V
    //   288: return
    //   289: astore 9
    //   291: aload 9
    //   293: invokevirtual 83	java/io/IOException:printStackTrace	()V
    //   296: return
    //   297: astore 7
    //   299: aload 4
    //   301: ifnull +8 -> 309
    //   304: aload 4
    //   306: invokevirtual 80	java/io/FileWriter:close	()V
    //   309: aload 7
    //   311: athrow
    //   312: astore 8
    //   314: aload 8
    //   316: invokevirtual 83	java/io/IOException:printStackTrace	()V
    //   319: goto -10 -> 309
    //   322: astore 7
    //   324: aload 5
    //   326: astore 4
    //   328: goto -29 -> 299
    //   331: astore 6
    //   333: aload 5
    //   335: astore 4
    //   337: goto -64 -> 273
    //   340: astore 16
    //   342: aload 14
    //   344: astore 13
    //   346: goto -172 -> 174
    //   349: astore 15
    //   351: aload 14
    //   353: astore 13
    //   355: goto -207 -> 148
    //
    // Exception table:
    //   from	to	target	type
    //   111	123	146	java/io/IOException
    //   158	163	164	java/io/IOException
    //   111	123	172	finally
    //   148	153	172	finally
    //   179	184	187	java/io/IOException
    //   140	145	197	java/io/IOException
    //   257	262	263	java/io/IOException
    //   229	241	271	java/io/IOException
    //   283	288	289	java/io/IOException
    //   229	241	297	finally
    //   273	278	297	finally
    //   304	309	312	java/io/IOException
    //   241	252	322	finally
    //   241	252	331	java/io/IOException
    //   123	135	340	finally
    //   123	135	349	java/io/IOException
  }

  public void initSigner(String paramString1, String paramString2)
    throws Exception
  {
    this.signSenderBc = new SenderBcImpl();
    char[] arrayOfChar = paramString2.toCharArray();
    this.signSenderBc.initCertWithKey(paramString1, arrayOfChar);
    this.signSenderBc.setSignAlgorithm("SHA1WithRSA");
    versionFile = new File(new File(paramString1).getParentFile(), "dinpayRSAKeyVersion");
    if (versionFile.exists())
    {
      DINPAY_KEY_VERSION = new BufferedReader(new FileReader(versionFile)).readLine();
      return;
    }
    versionFile.createNewFile();
  }

  public String signByPriKey(String paramString)
  {
    try
    {
      String str1 = DERUtils.BytesToHexString(paramString.getBytes("UTF-8"));
      String str2 = new String(Base64.encode(this.signSenderBc.signMessage(str1.getBytes("UTF-8"))));
      return str2;
    }
    catch (Exception localException)
    {
      localException.printStackTrace();
    }
    return null;
  }

  public boolean validateSignByPubKey(String paramString1, String paramString2, String paramString3)
  {
    try
    {
      String str1 = DERUtils.BytesToHexString(paramString2.getBytes("UTF-8"));
      byte[] arrayOfByte = Base64.decode(paramString3);
      SignerAndEncryptedDigest localSignerAndEncryptedDigest = this.recipient.verifyAndParsePkcs7(str1.getBytes("UTF-8"), arrayOfByte);
      com.itrus.cert.X509Certificate localX509Certificate = com.itrus.cert.X509Certificate.getInstance(localSignerAndEncryptedDigest.getSigner());
      DERUtils.HexStringToBytes(new String(localSignerAndEncryptedDigest.getOriData()));
      checkDinpayKeyVersion(localX509Certificate.getSubjectDNString());
      String str2 = this.signSenderBc.getSignerCert().getSubjectX500Principal().getName();
      String str3 = str2.substring(3 + str2.indexOf("CN="));
      if (str3.contains(","))
        str3 = str3.substring(0, str3.indexOf(","));
      if (!paramString1.equals(str3))
        throw new RuntimeException("validate sign failed:merchant_code is not equal.merchant_code in pfx is " + str3 + ",but merchant_code in params is " + paramString1);
    }
    catch (Exception localException)
    {
      localException.printStackTrace();
      return false;
    }
    return true;
  }
}

/* Location:           C:\Users\user\Desktop\dd28_pcdd720\classes_dex2jar.jar
 * Qualified Name:     com.itrus.util.sign.RSAWithHardware
 * JD-Core Version:    0.6.2
 */